<?php

class UserController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }

	public function loginAction()
	{
		$this->view->form = new Form_Login();
	}
	
	public function authAction(){
		$request 	= $this->getRequest();
		$registry 	= Zend_Registry::getInstance();
		$auth		= Zend_Auth::getInstance(); 
		
		$DB = $registry->get('db');
		Zend_Debug::Dump($DB);
			
		$authAdapter = new Zend_Auth_Adapter_DbTable($DB);
		$authAdapter->setTableName('users')
					->setIdentityColumn('username')
					->setCredentialColumn('password');    
		
		// Set the input credential values
		$uname = $request->getParam('username');
		$paswd = $request->getParam('password');
		$authAdapter->setIdentity($uname);
		//$authAdapter->setCredential(md5($paswd));
		$authAdapter->setCredential($paswd);

		// Perform the authentication query, saving the result
		$result = $auth->authenticate($authAdapter);

		if($result->isValid()){
			$data = $authAdapter->getResultRowObject(null,'password');
			$auth->getStorage()->write($data);
			$this->_redirect('/klacht/');
		}else{
			$this->_redirect('/user/login');
		}
	 }

	
}

